<template>
    <uni-popup ref="textEdit" type="center">
        <div class="edit_container">
            <div class="title">{{title}}</div>
            <div class="textarea">
                <textarea maxlength="-1" v-model="content" :placeholder="placeholder" placeholder-class="placeholder"></textarea>
            </div>
            <div class="example" v-if="example">{{example}}</div>
            <div class="btns">
                <div class="btn" @click="cancel">取消</div>
                <div class="btn" @click="confirm">确定</div>
            </div>
        </div>
    </uni-popup>
</template>

<script>
export default {
    data() {
        return {
            promiseResolve: null,
            title: '请输入',
            placeholder: '请输入文字',
            example: '',
            content: ''
        }
    },
    methods: {
        open(options) {
            return new Promise((resolve, reject) => {
                this.promiseResolve = resolve
                this.$refs.textEdit.open()
                this.title = options.title || '请输入'
                this.placeholder = options.placeholder || '请输入文字'
                this.example = options.example || ''
                this.content = options.content || ''
            })
        },
        confirm() {
            this.promiseResolve(this.content)
            this.cancel()
        },
        cancel() {
            this.$refs.textEdit.close()
            this.content = ''
            this.title = ''
            this.placeholder = ''
            this.example = ''
        }
    }

}
</script>

<style lang="less" scoped>
.edit_container{
    width: 680rpx;
    border-radius: 20rpx;
    background: #fff;
    padding: 20rpx 30rpx;
    .title{
        height: 80rpx;
        font-size: 34rpx;
        font-weight: bold;
        text-align: center;
        line-height: 80rpx;
    }
    .textarea{
        width: 100%;
        textarea{
            width: 100%;
            height: 300rpx;
            padding: 20rpx;
            border: 1px solid #ddd;
            background: #f6f6f6;
            border-radius: 20rpx;
        }
    }
    .example{
        color: #999;
        line-height: 40rpx;
        margin-top: 20rpx;
    }
    .btns{
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-top: 20rpx;
        .btn{
            width: 45%;
            height: 80rpx;
            background: @mainColor;
            .align(center);
            color: #fff;
            border-radius: 10rpx;
            font-size: 32rpx;
            &:first-child{
                background: #f4f5f7;
                color: #000;
            }
        }
    }
}

</style>